/*
 *  LAWL.cpp
 *  TubeTruck
 *
 *  Created by Aeturnum on 6/5/08.
 *  Copyright 2008 __MyCompanyName__. All rights reserved.
 *
 */

#include "LAWL.h"

using namespace std;
using namespace TTP;

/*
std::vector<byte> mGroupPublicKey;
*/

LAWL::LAWL() : Packet(Packet_LAWL)
{}
LAWL::LAWL(id_hash idHash) : Packet(idHash, Packet_LAWL)
{}
LAWL::LAWL(id_hash idHash, vector<byte>& sig, vector<byte>& groupPublicKey) :
Packet(idHash, Packet_LAWL), Signable(sig),
mGroupPublicKey(groupPublicKey)
{}

// accessors
vector<byte> LAWL::getGroupPublicKey() const {
   return mGroupPublicKey;
}

// modifier
void LAWL::setGroupPublicKey(vector<byte>& groupPublicKey) {
   mGroupPublicKey = groupPublicKey;
}

// idHash
void LAWL::setDestIdHash(id_hash idHash) {
   mIdHash = idHash;
}

uint32_t LAWL::getDestIdHash() const {
   return mIdHash;
}


// inherited
void LAWL::fromVec(vector<byte>::const_iterator &vit, vector<byte>::const_iterator &end) {
//   cout << "\nFrom Vec:\n";
   Packet::fromVec(vit, end);
   
   mSig.fromVec(vit, end);
//   cout << "mSig(" << mSig.size() <<"):\n" << mSig;
   mGroupPublicKey.insert(mGroupPublicKey.end(), vit, vit+Crypt::RSA::RSAKeyLength);
//   cout << "mGroupPublicKey(" << mGroupPublicKey.size() <<"):\n" << mGroupPublicKey;
   vit = vit+Crypt::RSA::RSAKeyLength;
}

void LAWL::toVec(vector<byte> &vec) const {
   Packet::toVec(vec);
   
//   cout << "mSig(" << mSig.size() <<"):\n" << mSig;
   mSig.toVec(vec);
//      cout << "mGroupPublicKey(" << mGroupPublicKey.size() <<"):\n" << mGroupPublicKey;
   vec.insert(vec.end(), mGroupPublicKey.begin(), mGroupPublicKey.end());
}

vector<byte> LAWL::getUnsignedData() const {
   vector<byte> toSign;
   vector<byte> blankSig = mSig.getBlankSigniture();
   
   Packet::toVec(toSign);
   
   toSign.insert(toSign.end(), blankSig.begin(), blankSig.end());
   toSign.insert(toSign.end(), mGroupPublicKey.begin(), mGroupPublicKey.end());
   return toSign;
}


